package control;

public class VerticalSlider extends Control {
	protected int min;
	protected int max;
	protected int value;
	int x, y;
	int w, h;

	public VerticalSlider(int min, int max, int x, int y, int w, int h) {
		this.min = min;
		this.max = max;
		this.value = min;
		this.x = x;
		this.y = y;
		this.w = w;
		this.h = h;
	}

	public int getValue() {
		return value;
	}

	public void setValue(int value) {
		this.value = value;
	}

	protected boolean isHover(int x, int y) {
		return (x > this.x && y > this.y && x <= this.x + this.w && y <= this.y
				+ this.h);
	}

	public boolean pointerPressed(int x, int y) {
		if (isHover(x, y)) {
			int l = y - this.y;
			value = min + (max - min) * l / this.h;

			if (command != null) {
				command.Do();
			}
			return true;
		}
		return false;
	}

	public boolean pointerReleased(int x, int y) {
		if (isHover(x, y)) {
			return true;
		}
		return false;
	}
}
